# RUN: yaml2obj %s -o %t
# RUN: llvm-objcopy %t %t2
# RUN: llvm-readobj --sections %t2 | FileCheck %s

## This checks that llvm-objcopy layouts sections in the order of their offsets
## in the input file in spite of the order of section headers is different.

# CHECK:      Index: 1
# CHECK-NEXT: Name: foo
# CHECK-NEXT: Type:
# CHECK-NEXT: Flags [
# CHECK-NEXT:   SHF_ALLOC
# CHECK-NEXT: ]
# CHECK-NEXT: Address:
# CHECK-NEXT: Offset: 0x50
# CHECK:      Index: 2
# CHECK-NEXT: Name: bar
# CHECK-NEXT: Type: SHT_PROGBITS
# CHECK-NEXT: Flags [
# CHECK-NEXT:   SHF_ALLOC
# CHECK-NEXT: ]
# CHECK-NEXT: Address:
# CHECK-NEXT: Offset: 0x40
# CHECK:      Index: 3
# CHECK-NEXT: Name: baz
# CHECK-NEXT: Type: SHT_PROGBITS
# CHECK-NEXT: Flags [
# CHECK-NEXT:   SHF_ALLOC
# CHECK-NEXT: ]
# CHECK-NEXT: Address:
# CHECK-NEXT: Offset: 0x48

--- !ELF
FileHeader:
  Class:           ELFCLASS64
  Data:            ELFDATA2LSB
  Type:            ET_REL
  Machine:         EM_X86_64
Sections:
  - Name:            bar
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC ]
    AddressAlign:    0x4
    Offset:          0x40
    Content:         0000000000000000
  - Name:            baz
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC ]
    AddressAlign:    0x4
    Offset:          0x48
    Content:         0000000000000000
  - Name:            foo
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC ]
    AddressAlign:    0x4
    Offset:          0x50
    Content:         0000000000000000
  - Type:            SectionHeaderTable
    Sections:
## Note: the order of section headers differs from their layout.
      - Name:            foo
      - Name:            bar
      - Name:            baz
      - Name:            .shstrtab
      - Name:            .strtab
